﻿using System.Collections.Generic;

namespace Gmantis.Controls.Extended
{
    internal class FixedQueue<T>
    {
        // Fields
        private List<T> _queue;

        // Methods
        public FixedQueue(int capacity)
        {
            this._queue = new List<T>();
            this.Capacity = capacity;
        }

        public void Clear()
        {
            this._queue.Clear();
        }

        public bool Contains(T item)
        {
            return this._queue.Contains(item);
        }

        public void Enqueue(T item)
        {
            if (this._queue.Count == this.Capacity)
            {
                this._queue.RemoveAt(0);
            }
            this._queue.Add(item);
        }

        public void ForceEnqueue(T item)
        {
            if (this._queue.Contains(item))
            {
                this._queue.Remove(item);
                this._queue.Add(item);
            }
        }

        public IList<T> ToList()
        {
            return new List<T>(this._queue);
        }

        // Properties
        public int Capacity { get; private set; }

        public int Count
        {
            get
            {
                return this._queue.Count;
            }
        }
    }
}
